package com.mzj.saas.rent;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.pojo.RecommendGroup;
import com.haixiaoke.saas.repository.service.IAreaService;
import com.haixiaoke.saas.repository.service.IRecommendGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 首页推荐公寓 Controller
 *
 * @author zhiping
 */
@RestController
@RequestMapping("/index/apartment")
public class RecommendController {

    @Autowired
    private IRecommendGroupService recommendGroupService;
    @Autowired
    private IAreaService iAreaService;

    @GetMapping("/recommend/{cityId}")
    public AjaxResult recommend(@PathVariable("cityId") Long city) {
        RecommendGroup recommendGroup = new RecommendGroup();
        recommendGroup.setCityId(city);
        return AjaxResult.success(recommendGroupService.selectRecommendGroupList(recommendGroup));
    }

    @GetMapping("/recommendByDistrictId/{districtId}")
    public AjaxResult recommendByDistrictId(@PathVariable("districtId") Long districtId) {
        Long cityId = iAreaService.selectCityByDistrictId(districtId);
        RecommendGroup recommendGroup = new RecommendGroup();
        recommendGroup.setCityId(cityId);
        return AjaxResult.success(recommendGroupService.selectRecommendGroupList(recommendGroup));
    }

}
